package com.yic.module.device.dal.mysql.deviceCategory;

import java.util.*;

import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yic.framework.mybatis.core.mapper.BaseMapperX;
import com.yic.module.device.dal.dataobject.deviceCategory.DeviceCategoryDO;
import org.apache.ibatis.annotations.Mapper;
import com.yic.module.device.controller.admin.deviceCategory.vo.*;

/**
 * 设备分类 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface DeviceCategoryMapper extends BaseMapperX<DeviceCategoryDO> {

    default PageResult<DeviceCategoryDO> selectPage(DeviceCategoryPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DeviceCategoryDO>()
                .likeIfPresent(DeviceCategoryDO::getName, reqVO.getName())
                .likeIfPresent(DeviceCategoryDO::getCode, reqVO.getCode())
                .eqIfPresent(DeviceCategoryDO::getStatus, reqVO.getStatus())
                .orderByDesc(DeviceCategoryDO::getId));
    }

    default List<DeviceCategoryDO> selectList(DeviceCategoryExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<DeviceCategoryDO>()
                .likeIfPresent(DeviceCategoryDO::getName, reqVO.getName())
                .likeIfPresent(DeviceCategoryDO::getCode, reqVO.getCode())
                .eqIfPresent(DeviceCategoryDO::getStatus, reqVO.getStatus())
                .orderByDesc(DeviceCategoryDO::getId));
    }

    default List<DeviceCategoryDO> selectList(DeviceCategoryReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<DeviceCategoryDO>()
                .likeIfPresent(DeviceCategoryDO::getName, reqVO.getName())
                .eqIfPresent(DeviceCategoryDO::getCode, reqVO.getCode())
                .eqIfPresent(DeviceCategoryDO::getStatus, reqVO.getStatus())
                .orderByDesc(DeviceCategoryDO::getId));
    }

    default List<DeviceCategoryDO> selectListByParentId(Collection<Long> parentIds) {
        return selectList(new LambdaQueryWrapperX<DeviceCategoryDO>()
                .inIfPresent(DeviceCategoryDO::getParentId, parentIds));
    }

    default DeviceCategoryDO selectByParentIdAndName(Long parentId, String name) {
        return selectOne(new LambdaQueryWrapperX<DeviceCategoryDO>()
                .eq(DeviceCategoryDO::getParentId, parentId)
                .eq(DeviceCategoryDO::getName, name));
    }

    default DeviceCategoryDO selectByCode(String code) {
        return selectOne(new LambdaQueryWrapperX<DeviceCategoryDO>()
                .eq(DeviceCategoryDO::getCode, code));
    }

    default Long selectChildCount(Long id) {
        return selectCount(new LambdaQueryWrapperX<DeviceCategoryDO>()
                .eq(DeviceCategoryDO::getId, id));
    }
}
